package com.yanqu.road.dataHelper.action.zhounianqing;

import com.yanqu.road.dataHelper.action.excel.ZhouNianQingRankData;
import com.yanqu.road.dataHelper.action.excel.ZhouNianRankLogic;
import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.ServerMgr;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.servercenter.ServerInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

public class UserEarnsDataETLCaller implements Callable<List<ZhouNianQingRankData>> {

    private List<Integer> eventType;

    private int rankType;

    ServerInfo serverInfo;

    int size;

    public UserEarnsDataETLCaller(List<Integer> eventType, int rankType, ServerInfo serverInfo, int size) {
        this.eventType = eventType;
        this.rankType = rankType;
        this.serverInfo = serverInfo;
        this.size = size;
    }

    @Override
    public List<ZhouNianQingRankData> call() throws Exception {
        GameServer testGameServer = new GameServer(serverInfo);
        ZhouNianRankLogic resource = new ZhouNianRankLogic(testGameServer);
        //List<ZhouNianQingRankData> serverRankList = resource.getServerRankList(serverInfo.getServerId(), eventType, size, rankType);

        List<ZhouNianQingRankData> serverRankList = new ArrayList<>();
        //赚钱冲榜
        //本服    1       2
        //跨服    12       1
        Map<Integer, ActivityInfo> activityInfoMap = new ServerMgr().getActivityInfoBy(1, 2, 12, 1, serverInfo.getServerId(), "2021-02-25 00:00:00", "2022-08-15 00:00:00");
        if(activityInfoMap.size() > 0){
            List<Integer> activityIdList = new ArrayList<>();
            for (int id : activityInfoMap.keySet()) {
                activityIdList.add(id);
            }
            serverRankList = resource.getServerRankListByActivityId(serverInfo.getServerId(), activityIdList, size, rankType);
        }

        if(serverRankList.size() > 0) {
            //填充活动数据
            //resource.fillActivityInfo(serverRankList);
            for (ZhouNianQingRankData rankData : serverRankList) {
                if(activityInfoMap.containsKey(rankData.getActivityId())) {
                    rankData.setDataTime(activityInfoMap.get(rankData.getActivityId()).getEndTime());
                }
            }
        }else {
            System.out.println("区服没有赚速冲榜：" + serverInfo.getServerId());
            return serverRankList;
        }

        //赚钱
        //总赚速|店铺编号|店铺等级|店铺赚钱
        //TODO  最高店铺赚速
        for (ZhouNianQingRankData rankData : serverRankList) {
            //最高店铺
            UserInfo userInfo = resource.getUserInfo(rankData.getUserId());
            if(userInfo != null){

            }

        }


        return serverRankList;
    }
}
